package org.vt.ece3574.pictoslider.facebook;

import android.os.Bundle;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;

/**
 * Listener to determine when a posting action has completed.
 * 
 * @author Michael
 */
public class FacebookDialogListener implements DialogListener {

	/**
	 * The facebook manager which corresponds to this listener.
	 */
	private FacebookManager fbManager;
	/**
	 * The asynchronous facebook runner which corresponds to this listener.
	 */
	private AsyncFacebookRunner runner;

	/**
	 * Constructor for this class.
	 * 
	 * @param f
	 *            - The facebook manager which corresponds to this listener.
	 * @param r
	 *            - The asynchronous facebook runner which corresponds to this
	 *            listener.
	 */
	public FacebookDialogListener(FacebookManager f, AsyncFacebookRunner r) {
		fbManager = f;
		runner = r;
	}

	/* (non-Javadoc)
	 * @see com.facebook.android.Facebook.DialogListener#onComplete(android.os.Bundle)
	 */
	public void onComplete(Bundle values) {
		if (values.getString("post_id") != null) {
			runner.request(values, new FacebookRequestListener(fbManager));
		}

	}

	/* (non-Javadoc)
	 * @see com.facebook.android.Facebook.DialogListener#onFacebookError(com.facebook.android.FacebookError)
	 */
	public void onFacebookError(FacebookError e) {
		e.printStackTrace();
	}

	/* (non-Javadoc)
	 * @see com.facebook.android.Facebook.DialogListener#onError(com.facebook.android.DialogError)
	 */
	public void onError(DialogError e) {
		e.printStackTrace();
	}

	/* (non-Javadoc)
	 * @see com.facebook.android.Facebook.DialogListener#onCancel()
	 */
	public void onCancel() {
	}

}
